<?php

namespace Common\TagLib;
use Think\Template\TagLib;
/**
*   前台导航自定义标签
*/
class Article extends TagLib
{
	
	// 标签定义
    protected $tags   =  array(
    	'list'     => array('attr' => 'cid,limit,field,sort'),
    	'category' => array('attr' => 'cid'),
    );

    public function _list( $tag, $content) {
    	if(isset($tag['cid'])) {
    		$where = "category_id = {$tag['cid']}";
    	}else{
    		$where = "";
    	}
    	$str = <<<str
<?php
    \$article = M('Article')->where("{$where}")->field("{$tag['field']}")->limit({$tag['limit']})->order("{$tag['sort']}")->select();
    foreach (\$article as \$v) :
?>
str;
        $str .= $content;
        $str .= "<?php endforeach;?>";
        return $str;
    }
}